<?php

/**
 * MVM_MALL 网上商店系统  配送插件管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-14 $
 * $Id: shipping.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if ($action=='list') {
    $list = get_dirinfo(MVMMALL_ROOT.'./include/shipping','.class.php');
    for ($i = 0; $i < count($list); $i++) {
        require MVMMALL_ROOT.'./include/shipping/'.$list[$i];
        $name = dhtmlchars(str_replace('.class.php','',$list[$i]));
        $ship = $db->get_one("SELECT id,class_name FROM `{$tablepre}ship_table` WHERE class_name='$name'");
        if($ship['class_name']){
            $shipping[$ship['class_name']]['install'] = 1;
            $shipping[$ship['class_name']]['id']      = $ship['id'];
            $shipping[$ship['class_name']]['edit']    = "admincp.php?module=area&action=list&ship_id=$ship[id]";
            $shipping[$ship['class_name']]['del']     = "admincp.php?module=$module&action=del&uid=$ship[id]";
        }
        $shipping[$name]['insert']                    = "admincp.php?module=$module&action=add&name=$name";
        $shipping[$name]['cod']                       = $ship['cod']==1 ? $lang['yes'] :$lang['no'];
    }
    require template('shipping');
    footer();
} elseif ($action=='add' && isset($name)) {
    $name    = dhtmlchars($name);
    $ship    = $db->get_one("SELECT id,class_name FROM `{$tablepre}ship_table` WHERE class_name='$name'");
    if($ship['class_name']){
        $db->query("UPDATE `{$tablepre}ship_table` SET enabled = 1 WHERE class_name='$name' LIMIT 1");
    } else {
        require MVMMALL_ROOT.'./include/shipping/'.$name.'.class.php';
        $ship_name = dhtmlchars($shipping[$name]['name']);
        $ship_desc = dhtmlchars($shipping[$name]['desc']);
        $db->query("INSERT INTO `{$tablepre}ship_table` SET class_name = '$name',name = '$ship_name',ship_desc = '$ship_desc'");
    }
    $cache->put_cache('shipping');
    admin_msg('success','admincp.php?module=shipping&action=list');
} elseif ($action=='del' && is_numeric($uid)){
    $db->query("DELETE FROM `{$tablepre}ship_table` WHERE id = '$uid'");
    $db->query("DELETE FROM `{$tablepre}area_table` WHERE ship_id = '$uid'");
    $cache->put_cache('shipping');
    admin_msg('success','admincp.php?module=shipping&action=list');
} else {
    admin_msg('pass_worng');
}